package chapter11.exercise.test05;

import static com.common.utils.Print.print;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class ListFeatures {
    public static void main(String[] args) {
        Random rand = new Random(47);
        List<Integer> integers = new ArrayList();
        Collections.addAll(integers, 1, 8, 98, 5, 23, 7, 4, 5, 6);
        print("1: " + integers);
        Integer i = 110;
        integers.add(i);
        print("2: " + integers);
        print("3: " + integers.contains(i));
        integers.remove(i);
        Integer i2 = integers.get(2);
        print("4: " + i2 + " " + integers.indexOf(i2));
        Integer i3 = 120;
        print("5: " + integers.indexOf(i3));
        print("6: " + integers.remove(i3));

        print("7: " + integers.remove(i2));
        print("8: " + integers);
        integers.add(3, new Integer(119));
        print("9: " + integers);
        List<Integer> sub = integers.subList(1, 4);
        print("subList: " + sub);
        print("10: " + integers.containsAll(sub));
        Collections.sort(sub);
        print("sorted subList: " + sub);
        print("11: " + integers.containsAll(sub));
        Collections.shuffle(sub);
        print("shuffle subList: " + sub);
        print("12: " + integers.containsAll(sub));

        sub = Arrays.asList(integers.get(1), integers.get(4));
        integers.retainAll(sub);
        print(integers);

    }
}
